<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>css单位测试</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            font-size: 16px;
        }
        .box {
            width: 100vw;
            height: 100vh;
            background-color: antiquewhite;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            font-size: 16px;
        }
        .box div {
            display: flex;
            justify-content: center;
            align-items: center;
            border: 1px solid;
        }
        .child1 {
            width: 25vw;
            height: 25vw;
            background: red;
            font-size: 16px;
        }
        .child2 {
            width: 10em;
            height: 10em;
            background: rgb(40, 138, 219);
            font-size: 20px;
        }
        .child3 {
            width: 10rem;
            height: 10rem;
            background: rgb(220, 157, 31);
            font-size: 16px;
        }
        .child4 {
            width: 25%;
            height: 25%;
            background: rgb(24, 228, 78);
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="child1">
            child1 宽高25vw
        </div>
        <div class="child2">
            child2 宽高 10em  font-size: 20px
        </div>
        <div class="child3">
            child3 宽高 10rem
        </div>
        <div class="child4">
            child4 宽高 25%
        </div>
    </div>
    <script>
        const resize = () => {
            console.log('屏幕大小正在发生变化。。。')
            const designW = 1920
            const innweW = window.innerWidth
            const w = innweW/designW * 50
            const html = document.querySelector('html')
            html.style.fontSize = `${w}px`
        }
        resize()

  
        // window.onresize = resize
        window.addEventListener('resize', resize)
        window.addEventListener('resize', ()=> {
            console.log('add测试')
        })
        window.addEventListener('resize', ()=> {
            console.log('add测试1')
        })
    </script>
</body>
</html>